package light.mvc.controller.record;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import light.mvc.controller.base.BaseController;
import light.mvc.pageModel.base.Grid;
import light.mvc.pageModel.base.Json;
import light.mvc.pageModel.base.PageFilter;
import light.mvc.pageModel.record.Room;
import light.mvc.service.record.RoomServiceI;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping( { "/room" })
public class RoomController extends BaseController {
	@Autowired
	private RoomServiceI roomServiceImpl;
	
	@RequestMapping( { "/dataGrid" })
	@ResponseBody
	public Grid dataGrid(Room room, PageFilter ph) {
		Grid grid = new Grid();
		grid.setRows(this.roomServiceImpl.dataGrid(room, ph));
		grid.setTotal(this.roomServiceImpl.count(room, ph));
		return grid;
	}
	@RequestMapping( { "/getAllRoom" })
	@ResponseBody
	public List<Room> getAllRoom(Room room, PageFilter ph) {
		List<Room> rooms = this.roomServiceImpl.getAllRoomUsedForDel();
		return rooms;
	}
	
	
	@RequestMapping( { "/deleteRoom" })
	@ResponseBody
	public Json deleteRoom(HttpServletRequest request) {
		long id = Long.valueOf(request.getParameter("id"));

		Json json = new Json();
		this.roomServiceImpl.delById(id);
		json.setSuccess(true);
		return json;
	} 
}
